home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / Mesa-3.0 / SRC / MGL / MMESAI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-30  |  25.2 KB  |  356 lines

  1. /****************************************************************************
  2. *
  3. *                        Mesa bindings for SciTech MGL
  4. *
  5. *               Copyright (C) 1996-1998 SciTech Software, Inc.
  6. *                            All rights reserved.
  7. *
  8. * Language:     ANSI C
  9. * Environment:    Any
  10. *
  11. * Description:    Include file defining macros to implement many of the
  12. *                optimized rendering functions for the MGL Mesa driver.
  13. *
  14. * This library is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU Library General Public
  16. * License as published by the Free Software Foundation; either
  17. * version 2 of the License, or (at your option) any later version.
  18. *
  19. * This library is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22. * Library General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Library General Public
  25. * License along with this library; if not, write to the Free
  26. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  27. *
  28. ****************************************************************************/
  29.  
  30. /**********************************************************************/
  31. /*****            Write spans of pixels                           *****/
  32. /**********************************************************************/
  33.  
  34. #define    IMPLEMENT_WRITE_SPAN(DEPTH,FMT,TYPE)                                 \
  35. void _mmesa_write_span_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x,    \
  36.     GLint y,GLubyte rgba[][4],GLubyte mask[])                               \
  37. {                                                                           \
  38.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                         \
  39.     if (mask) {                                                             \
  40.         while (n >= 8) {                                                    \
  41.             if (mask[0]) d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);  \
  42.             if (mask[1]) d[1] = PACK_COLOR_##FMT(rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);  \
  43.             if (mask[2]) d[2] = PACK_COLOR_##FMT(rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);  \
  44.             if (mask[3]) d[3] = PACK_COLOR_##FMT(rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);  \
  45.             if (mask[4]) d[4] = PACK_COLOR_##FMT(rgba[4][RCOMP],rgba[4][GCOMP],rgba[4][BCOMP]);  \
  46.             if (mask[5]) d[5] = PACK_COLOR_##FMT(rgba[5][RCOMP],rgba[5][GCOMP],rgba[5][BCOMP]);  \
  47.             if (mask[6]) d[6] = PACK_COLOR_##FMT(rgba[6][RCOMP],rgba[6][GCOMP],rgba[6][BCOMP]);  \
  48.             if (mask[7]) d[7] = PACK_COLOR_##FMT(rgba[7][RCOMP],rgba[7][GCOMP],rgba[7][BCOMP]);  \
  49.             d += 8; rgba += 8; mask += 8; n -= 8;                             \
  50.             }                                                               \
  51.         while (n--) {                                                       \
  52.             if (mask[0]) d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);  \
  53.             d++; rgba++; mask++;                                            \
  54.             }                                                               \
  55.         }                                                                   \
  56.     else {                                                                  \
  57.         while (n >= 8) {                                                    \
  58.             d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);               \
  59.             d[1] = PACK_COLOR_##FMT(rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);               \
  60.             d[2] = PACK_COLOR_##FMT(rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);               \
  61.             d[3] = PACK_COLOR_##FMT(rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);               \
  62.             d[4] = PACK_COLOR_##FMT(rgba[4][RCOMP],rgba[4][GCOMP],rgba[4][BCOMP]);               \
  63.             d[5] = PACK_COLOR_##FMT(rgba[5][RCOMP],rgba[5][GCOMP],rgba[5][BCOMP]);               \
  64.             d[6] = PACK_COLOR_##FMT(rgba[6][RCOMP],rgba[6][GCOMP],rgba[6][BCOMP]);               \
  65.             d[7] = PACK_COLOR_##FMT(rgba[7][RCOMP],rgba[7][GCOMP],rgba[7][BCOMP]);               \
  66.             d += 8; rgba += 8; n -= 8;                                        \
  67.             }                                                               \
  68.         while (n--) {                                                       \
  69.             d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);\
  70.             d++; rgba++;                                                    \
  71.             }                                                               \
  72.         }                                                                   \
  73. }
  74.  
  75. #define    IMPLEMENT_WRITE_SPAN_RGB(DEPTH,FMT,TYPE)                                 \
  76. void _mmesa_write_span_rgb_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x,    \
  77.     GLint y,GLubyte rgba[][3],GLubyte mask[])                               \
  78. {                                                                           \
  79.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                         \
  80.     if (mask) {                                                             \
  81.         while (n >= 8) {                                                    \
  82.             if (mask[0]) d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);  \
  83.             if (mask[1]) d[1] = PACK_COLOR_##FMT(rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);  \
  84.             if (mask[2]) d[2] = PACK_COLOR_##FMT(rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);  \
  85.             if (mask[3]) d[3] = PACK_COLOR_##FMT(rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);  \
  86.             if (mask[4]) d[4] = PACK_COLOR_##FMT(rgba[4][RCOMP],rgba[4][GCOMP],rgba[4][BCOMP]);  \
  87.             if (mask[5]) d[5] = PACK_COLOR_##FMT(rgba[5][RCOMP],rgba[5][GCOMP],rgba[5][BCOMP]);  \
  88.             if (mask[6]) d[6] = PACK_COLOR_##FMT(rgba[6][RCOMP],rgba[6][GCOMP],rgba[6][BCOMP]);  \
  89.             if (mask[7]) d[7] = PACK_COLOR_##FMT(rgba[7][RCOMP],rgba[7][GCOMP],rgba[7][BCOMP]);  \
  90.             d += 8; rgba += 8; mask += 8; n -= 8;                             \
  91.             }                                                               \
  92.         while (n--) {                                                       \
  93.             if (mask[0]) d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);  \
  94.             d++; rgba++; mask++;                                            \
  95.             }                                                               \
  96.         }                                                                   \
  97.     else {                                                                  \
  98.         while (n >= 8) {                                                    \
  99.             d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);               \
  100.             d[1] = PACK_COLOR_##FMT(rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);               \
  101.             d[2] = PACK_COLOR_##FMT(rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);               \
  102.             d[3] = PACK_COLOR_##FMT(rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);               \
  103.             d[4] = PACK_COLOR_##FMT(rgba[4][RCOMP],rgba[4][GCOMP],rgba[4][BCOMP]);               \
  104.             d[5] = PACK_COLOR_##FMT(rgba[5][RCOMP],rgba[5][GCOMP],rgba[5][BCOMP]);               \
  105.             d[6] = PACK_COLOR_##FMT(rgba[6][RCOMP],rgba[6][GCOMP],rgba[6][BCOMP]);               \
  106.             d[7] = PACK_COLOR_##FMT(rgba[7][RCOMP],rgba[7][GCOMP],rgba[7][BCOMP]);               \
  107.             d += 8; rgba += 8; n -= 8;                                        \
  108.             }                                                               \
  109.         while (n--) {                                                       \
  110.             d[0] = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);\
  111.             d++; rgba++;                                                    \
  112.             }                                                               \
  113.         }                                                                   \
  114. }
  115.  
  116. #define    IMPLEMENT_WRITE_SPAN_DITHER(DEPTH,FMT,TYPE)                         \
  117. void _mmesa_write_span_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x,    \
  118.     GLint y,GLubyte rgba[][4],GLubyte mask[])                               \
  119. {                                                                                   \
  120.     TYPE *d;                                                                        \
  121.     y = FLIP(y);                                                                    \
  122.     d = PACKED##DEPTH##_pixelAddr(x,y);                                             \
  123.     if (mask) {                                                                     \
  124.         while (n >= 4) {                                                            \
  125.             if (mask[0]) PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);        \
  126.             if (mask[1]) PACK_COLOR_##FMT(d[1],x+1,y,rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);      \
  127.             if (mask[2]) PACK_COLOR_##FMT(d[2],x+2,y,rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);      \
  128.             if (mask[3]) PACK_COLOR_##FMT(d[3],x+3,y,rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);      \
  129.             d += 4; rgba += 4; mask += 4; x += 4; n -= 4;                             \
  130.             }                                                                       \
  131.         while (n--) {                                                               \
  132.             if (mask[0]) PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);        \
  133.             d++; rgba++; mask++; x++;                                               \
  134.             }                                                                       \
  135.         }                                                                           \
  136.     else {                                                                          \
  137.         while (n >= 4) {                                                            \
  138.             PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);                     \
  139.             PACK_COLOR_##FMT(d[1],x+1,y,rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);                   \
  140.             PACK_COLOR_##FMT(d[2],x+2,y,rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);                   \
  141.             PACK_COLOR_##FMT(d[3],x+3,y,rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);                   \
  142.             d += 4; rgba += 4; x += 4; n -= 4;                                        \
  143.             }                                                                       \
  144.         while (n--) {                                                               \
  145.             PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);                     \
  146.             d++; rgba++; x++;                                                       \
  147.             }                                                                       \
  148.         }                                                                           \
  149. }
  150.  
  151. #define    IMPLEMENT_WRITE_SPAN_RGB_DITHER(DEPTH,FMT,TYPE)                         \
  152. void _mmesa_write_span_rgb_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x,    \
  153.     GLint y,GLubyte rgba[][3],GLubyte mask[])                                   \
  154. {                                                                                   \
  155.     TYPE *d;                                                                        \
  156.     y = FLIP(y);                                                                    \
  157.     d = PACKED##DEPTH##_pixelAddr(x,y);                                             \
  158.     if (mask) {                                                                     \
  159.         while (n >= 4) {                                                            \
  160.             if (mask[0]) PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);        \
  161.             if (mask[1]) PACK_COLOR_##FMT(d[1],x+1,y,rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);      \
  162.             if (mask[2]) PACK_COLOR_##FMT(d[2],x+2,y,rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);      \
  163.             if (mask[3]) PACK_COLOR_##FMT(d[3],x+3,y,rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);      \
  164.             d += 4; rgba += 4; mask += 4; x += 4; n -= 4;                             \
  165.             }                                                                       \
  166.         while (n--) {                                                               \
  167.             if (mask[0]) PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);        \
  168.             d++; rgba++; mask++; x++;                                               \
  169.             }                                                                       \
  170.         }                                                                           \
  171.     else {                                                                          \
  172.         while (n >= 4) {                                                            \
  173.             PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);                     \
  174.             PACK_COLOR_##FMT(d[1],x+1,y,rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);                   \
  175.             PACK_COLOR_##FMT(d[2],x+2,y,rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);                   \
  176.             PACK_COLOR_##FMT(d[3],x+3,y,rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);                   \
  177.             d += 4; rgba += 4; x += 4; n -= 4;                                        \
  178.             }                                                                       \
  179.         while (n--) {                                                               \
  180.             PACK_COLOR_##FMT(d[0],x,y,rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);                     \
  181.             d++; rgba++; x++;                                                       \
  182.             }                                                                       \
  183.         }                                                                           \
  184. }
  185.  
  186. #define    IMPLEMENT_WRITE_SPAN_MONO(DEPTH,TYPE)                                \
  187. void _mmesa_write_span_mono_##DEPTH (GLcontext *ctx,GLuint n,GLint x,        \
  188.     GLint y,GLubyte mask[])                                                 \
  189. {                                                                           \
  190.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                         \
  191.     while (n >= 8) {                                                        \
  192.         if (mask[0]) d[0] = (TYPE)RC.color;                                 \
  193.         if (mask[1]) d[1] = (TYPE)RC.color;                                 \
  194.         if (mask[2]) d[2] = (TYPE)RC.color;                                 \
  195.         if (mask[3]) d[3] = (TYPE)RC.color;                                 \
  196.         if (mask[4]) d[4] = (TYPE)RC.color;                                 \
  197.         if (mask[5]) d[5] = (TYPE)RC.color;                                 \
  198.         if (mask[6]) d[6] = (TYPE)RC.color;                                 \
  199.         if (mask[7]) d[7] = (TYPE)RC.color;                                 \
  200.         d += 8; mask += 8; n -= 8;                                          \
  201.         }                                                                   \
  202.     while (n--) {                                                           \
  203.         if (mask[0]) d[0] = (TYPE)RC.color;                                 \
  204.         d++; mask++;                                                        \
  205.         }                                                                   \
  206. }
  207.  
  208. #define    IMPLEMENT_WRITE_SPAN_MONO_DITHER(DEPTH,FMT,TYPE)                        \
  209. void _mmesa_write_span_mono_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x,    \
  210.     GLint y,GLubyte mask[])                                                     \
  211. {                                                                               \
  212.     HALFTONE_VARS_##DEPTH;                                                      \
  213.     TYPE *d;                                                                    \
  214.     y = FLIP(y);                                                                \
  215.     d = PACKED##DEPTH##_pixelAddr(x,y);                                         \
  216.     SETUP_##FMT(y,RC.red,RC.green,RC.blue);                                     \
  217.     while (n >= 4) {                                                            \
  218.         if (mask[0]) PACK_COLOR2_##FMT(d[0],x);                                 \
  219.         if (mask[1]) PACK_COLOR2_##FMT(d[1],x+1);                               \
  220.         if (mask[2]) PACK_COLOR2_##FMT(d[2],x+2);                               \
  221.         if (mask[3]) PACK_COLOR2_##FMT(d[3],x+3);                               \
  222.         d += 4; mask += 4; x += 4; n -= 4;                                      \
  223.         }                                                                       \
  224.     while (n--) {                                                               \
  225.         if (mask[0]) PACK_COLOR2_##FMT(d[0],x);                                 \
  226.         d++; mask++; x++;                                                       \
  227.         }                                                                       \
  228. }
  229.  
  230. /**********************************************************************/
  231. /*****              Write arrays of pixels                        *****/
  232. /**********************************************************************/
  233.  
  234. #define    IMPLEMENT_WRITE_PIXELS(DEPTH,FMT,TYPE)                                                                    \
  235. void _mmesa_write_pixels_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x[],                                    \
  236.     GLint y[],GLubyte rgba[][4],GLubyte mask[])                                                                    \
  237. {                                                                                                               \
  238.     while (n >= 4) {                                                                                            \
  239.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);   \
  240.         if (mask[1]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[1],FLIP(y[1]))) = PACK_COLOR_##FMT(rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);   \
  241.         if (mask[2]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[2],FLIP(y[2]))) = PACK_COLOR_##FMT(rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);   \
  242.         if (mask[3]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[3],FLIP(y[3]))) = PACK_COLOR_##FMT(rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);   \
  243.         rgba += 4; mask += 4; x+= 4; y += 4; n -= 4;                                                               \
  244.         }                                                                                                       \
  245.     while (n--) {                                                                                               \
  246.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = PACK_COLOR_##FMT(rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);   \
  247.         rgba++; mask++; x++; y++;                                                                                \
  248.         }                                                                                                       \
  249. }                                                                                                               
  250.  
  251. #define IMPLEMENT_WRITE_PIXELS_DITHER(DEPTH,FMT,TYPE)                            \
  252. void _mmesa_write_pixels_##DEPTH##_##FMT(GLcontext *ctx,GLuint n, GLint x[],    \
  253.     GLint y[],GLubyte rgba[][4],GLubyte mask[])                                 \
  254. {                                                                               \
  255.     while (n--) {                                                               \
  256.         if (mask[0]) {                                                          \
  257.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));               \
  258.             PACK_COLOR_##FMT(d[0],x[0],FLIP(y[0]),rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]); \
  259.             }                                                                   \
  260.         rgba++; mask++; x++; y++;                                                \
  261.         }                                                                       \
  262. }                                                                               
  263.  
  264. #define    IMPLEMENT_WRITE_PIXELS_MONO(DEPTH,TYPE)                                                \
  265. void _mmesa_write_pixels_mono_##DEPTH (GLcontext *ctx,GLuint n,GLint x[],                   \
  266.     GLint y[],GLubyte mask[])                                                               \
  267. {                                                                                           \
  268.     while (n >= 4) {                                                                        \
  269.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = (TYPE)RC.color; \
  270.         if (mask[1]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[1],FLIP(y[1]))) = (TYPE)RC.color; \
  271.         if (mask[2]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[2],FLIP(y[2]))) = (TYPE)RC.color; \
  272.         if (mask[3]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[3],FLIP(y[3]))) = (TYPE)RC.color; \
  273.         mask += 4; x+= 4; y += 4; n -= 4;                                                   \
  274.         }                                                                                   \
  275.     while (n--) {                                                                           \
  276.         if (mask[0]) *((TYPE*)PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]))) = (TYPE)RC.color; \
  277.         mask++; x++; y++;                                                                   \
  278.         }                                                                                   \
  279. }
  280.  
  281. #define IMPLEMENT_WRITE_PIXELS_MONO_DITHER(DEPTH,FMT,TYPE)                            \
  282. void _mmesa_write_pixels_mono_##DEPTH##_##FMT(GLcontext *ctx,GLuint n,GLint x[],    \
  283.     GLint y[],GLubyte mask[])                                                       \
  284. {                                                                                   \
  285.     while (n--) {                                                                   \
  286.         if (mask[0]) {                                                              \
  287.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));                   \
  288.             PACK_COLOR_##FMT(d[0],x[0],FLIP(y[0]),RC.red,RC.green,RC.blue);         \
  289.             }                                                                       \
  290.         mask++; x++; y++;                                                           \
  291.         }                                                                           \
  292. }
  293.  
  294. /**********************************************************************/
  295. /*****                 Read spans of pixels                       *****/
  296. /**********************************************************************/
  297.  
  298. #define    IMPLEMENT_READ_SPAN(DEPTH,FMT,TYPE)                                            \
  299. void _mmesa_read_span_##DEPTH##_##FMT(GLcontext *ctx,GLuint n,GLint x,GLint y,        \
  300.     GLubyte rgba[][4])                                                                \
  301. {                                                                                   \
  302.     TYPE *d = PACKED##DEPTH##_pixelAddr(x,FLIP(y));                                 \
  303.     while (n >= 8) {                                                                \
  304.         UNPACK_COLOR_##FMT(d[0],rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);                           \
  305.         UNPACK_COLOR_##FMT(d[1],rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]);                           \
  306.         UNPACK_COLOR_##FMT(d[2],rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]);                           \
  307.         UNPACK_COLOR_##FMT(d[3],rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]);                           \
  308.         UNPACK_COLOR_##FMT(d[4],rgba[4][RCOMP],rgba[4][GCOMP],rgba[4][BCOMP]);                           \
  309.         UNPACK_COLOR_##FMT(d[5],rgba[5][RCOMP],rgba[5][GCOMP],rgba[5][BCOMP]);                           \
  310.         UNPACK_COLOR_##FMT(d[6],rgba[6][RCOMP],rgba[6][GCOMP],rgba[6][BCOMP]);                           \
  311.         UNPACK_COLOR_##FMT(d[7],rgba[7][RCOMP],rgba[7][GCOMP],rgba[7][BCOMP]);                           \
  312.         d += 8; rgba += 8; n -= 8;                                                    \
  313.         }                                                                           \
  314.     while (n--) {                                                                   \
  315.         UNPACK_COLOR_##FMT(d[0],rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]);      \
  316.         d++; rgba++;                                                                \
  317.         }                                                                           \
  318. }
  319.  
  320. /**********************************************************************/
  321. /*****                   Read arrays of pixels                    *****/
  322. /**********************************************************************/
  323.  
  324. #define    IMPLEMENT_READ_PIXELS(DEPTH,FMT,TYPE)                                    \
  325. void _mmesa_read_pixels_##DEPTH##_##FMT (GLcontext *ctx,GLuint n,GLint x[],        \
  326.     GLint y[],GLubyte rgba[][4],GLubyte mask[])                                    \
  327. {                                                                               \
  328.     while (n >= 4) {                                                            \
  329.         if (mask[0]) {                                                          \
  330.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));               \
  331.             UNPACK_COLOR_##FMT(d[0],rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]); \
  332.             }                                                                   \
  333.         if (mask[1]) {                                                          \
  334.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[1],FLIP(y[1]));               \
  335.             UNPACK_COLOR_##FMT(d[1],rgba[1][RCOMP],rgba[1][GCOMP],rgba[1][BCOMP]); \
  336.             }                                                                   \
  337.         if (mask[2]) {                                                          \
  338.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[2],FLIP(y[2]));               \
  339.             UNPACK_COLOR_##FMT(d[2],rgba[2][RCOMP],rgba[2][GCOMP],rgba[2][BCOMP]); \
  340.             }                                                                   \
  341.         if (mask[3]) {                                                          \
  342.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[3],FLIP(y[3]));               \
  343.             UNPACK_COLOR_##FMT(d[3],rgba[3][RCOMP],rgba[3][GCOMP],rgba[3][BCOMP]); \
  344.             }                                                                   \
  345.         rgba += 4; mask += 4; x += 4; y += 4; n -= 4;                             \
  346.         }                                                                       \
  347.     while (n--) {                                                               \
  348.         if (mask[0]) {                                                          \
  349.             TYPE *d = PACKED##DEPTH##_pixelAddr(x[0],FLIP(y[0]));               \
  350.             UNPACK_COLOR_##FMT(d[0],rgba[0][RCOMP],rgba[0][GCOMP],rgba[0][BCOMP]); \
  351.             }                                                                   \
  352.         rgba++; mask++; x++; y++;                                               \
  353.         }                                                                       \
  354. }
  355.  
  356.